package com.heima.三种注入方式;

import com.heima.分布式锁.StockController;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.lang.reflect.Field;

/**
 * @author 陈辉
 * @data 2023 11:34
 */

public class Demo {
    public static void main(String[] args) throws Exception {
        Class<StockController> clazz = StockController.class;
        Field template = clazz.getDeclaredField("template");
        StockController controller = new StockController();

        //判断当前属性有没有被注解标记
        if(template.isAnnotationPresent(heiheihei.class)){
            //标记了，则暴力反射，直接给属性赋值
            template.setAccessible(true);
            template.set(controller,new StringRedisTemplate());
        }

        String res = controller.stock01();
        System.out.println("res = " + res);
    }
}
